import os.path

from devicetest.aw.OpenHarmony import CommonOH
from devicetest.core.test_case import TestCase, Step

from aw.common import common_setup, common_teardown


class PreTest_RK3568_Basic_hap_0200(TestCase):
    # 预置条件：
    # 烧写目标版本后，正常进入桌面
    # 测试步骤：
    # 1、长按已安装的HAP包
    # 2、点击卸载
    # 预期结果：
    # 1、长按HAP包应用，显示卸载按钮
    # 2、点击卸载，也可取消卸载，且不影响其他应用使用

    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        TestCase.__init__(self, self.TAG, controllers)
        self.testcases_path = self.configs['testcases_path']
        self.hap_path = os.path.join(os.path.dirname(self.testcases_path), 'resource', 'hap', 'test_demo.hap')

    def setup(self):
        common_setup(self.Phone1)
        Step('预置条件2：安装hap包')
        CommonOH.installApp_r(self.Phone1, self.hap_path)

    def process(self):
        Step('步骤1：长按已安装的HAP包')
        label_x, label_y = CommonOH.getPointByCondition(self.Phone1, 'label')
        CommonOH.click(self.Phone1, x=label_x, y=label_y - 50, mode='LONG')
        Step('预期结果1：长按HAP包应用，显示卸载按钮')
        CommonOH.checkIfTextExist(self.Phone1, '卸载')

        Step('步骤2：点击卸载')
        CommonOH.touchByText(self.Phone1, '卸载')
        Step('预期结果2：点击卸载，也可取消卸载，且不影响其他应用使用')
        CommonOH.touchByText(self.Phone1, '取消')
        CommonOH.checkIfTextExist(self.Phone1, 'label')
        CommonOH.click(self.Phone1, x=label_x, y=label_y - 50, mode='LONG')
        CommonOH.touchByText(self.Phone1, '卸载')
        CommonOH.touchByText(self.Phone1, '卸载')
        CommonOH.checkIfTextExist(self.Phone1, 'label', expect=False)

    def teardown(self):
        common_teardown(self.Phone1)
